﻿<UserControl x:Class="TanmiaGrp.GeneralLedger.WinApp.Pages.GroupEditorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:loc="clr-namespace:TanmiaGrp.GeneralLedger.WinApp"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="300">

    <UserControl.Resources>

        <loc:NullToVisibilityConverter x:Key="nullConverter" />

        <ControlTemplate x:Key="ValidationTemplate">
            <StackPanel Orientation="Vertical">
                <Border BorderThickness="1"
                        BorderBrush="#FFdc000c"
                        VerticalAlignment="Top">
                    <Grid>
                        <AdornedElementPlaceholder x:Name="adorner"
                                                   Margin="-1" />
                    </Grid>
                </Border>
                <Border x:Name="errorBorder"
                        Background="#FFdc000c"
                        Opacity="0"
                        CornerRadius="0"
                        IsHitTestVisible="False"
                        MinHeight="20">
                    <TextBlock Text="{Binding ElementName=adorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"
                               Foreground="White"
                               Margin="8,1,8,3"
                               TextWrapping="Wrap"
                               VerticalAlignment="Center" />
                </Border>
            </StackPanel>
            <ControlTemplate.Triggers>
                <DataTrigger Value="True">
                    <DataTrigger.Binding>
                        <Binding ElementName="adorner"
                                 Path="AdornedElement.IsKeyboardFocused" />
                    </DataTrigger.Binding>
                    <DataTrigger.EnterActions>
                        <BeginStoryboard x:Name="fadeInStoryboard">
                            <Storyboard>
                                <DoubleAnimation Duration="00:00:00.15"
                                                 Storyboard.TargetName="errorBorder"
                                                 Storyboard.TargetProperty="Opacity"
                                                 To="1" />
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <StopStoryboard BeginStoryboardName="fadeInStoryboard" />
                        <BeginStoryboard x:Name="fadeOutStoryBoard">
                            <Storyboard>
                                <DoubleAnimation Duration="00:00:00"
                                                 Storyboard.TargetName="errorBorder"
                                                 Storyboard.TargetProperty="Opacity"
                                                 To="0" />
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.ExitActions>
                </DataTrigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

    </UserControl.Resources>

    <Grid Style="{StaticResource ContentRoot}">

        <Grid.Resources>
            <Style TargetType="HeaderedContentControl">
                <Setter Property="Focusable"
                        Value="False" />
                <Setter Property="Margin"
                        Value="0,0,0,5" />

            </Style>
        </Grid.Resources>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="20*" />
            <ColumnDefinition Width="80*" />
        </Grid.ColumnDefinitions>

        <StackPanel Grid.Column="0"
                    Orientation="Vertical"
                    Background="DarkGray">
            <Button Content="جديد"
                    Command="{Binding Path=NewCommand}" />
            <Button Content="حفظ"
                    Command="{Binding Path=SaveCommand}" />
            <Button Content="حفظ وجديد"
                    Command="{Binding Path=SaveAndNewCommand}" />

            <Button Content="حفظ واغلاق"
                    Command="{Binding Path=SaveAndCloseCommand}"
                    CommandParameter="{Binding RelativeSource={RelativeSource Self}}" />

            <Button Content="حذف"
                    Command="{Binding Path=DeleteCommand}"
                    CommandParameter="{Binding RelativeSource={RelativeSource Self}}" />

            <Button Content="الأول"
                    Command="{Binding Path=GoToForthEntityCommand}"
                    CommandParameter="{x:Static loc:NavigationMoveEnum.First}" />

            <Button Content="السابق"
                    Command="{Binding Path=GoToForthEntityCommand}"
                    CommandParameter="{x:Static loc:NavigationMoveEnum.Previous}" />

            <Button Content="التالي"
                    Command="{Binding Path=GoToBackEntityCommand}"
                    CommandParameter="{x:Static loc:NavigationMoveEnum.Next}" />

            <Button Content="الأخير"
                    Command="{Binding Path=GoToBackEntityCommand}"
                    CommandParameter="{x:Static loc:NavigationMoveEnum.Last}" />

            <Button Name="btnPopout" Content="فتح في نافذة جديدة"
                    Click="OnPopout" />

            <Button Content="اغلاق"
                    Command="{Binding Path=CloseCommand}"
                    CommandParameter="{Binding RelativeSource={RelativeSource Self}}" />
        </StackPanel>

        <Grid Grid.Column="1">
            <StackPanel Orientation="Vertical">

                <HeaderedContentControl Header="رقم المجموعة">
                    <TextBox Text="{Binding Path=Entity.GroupID}"
                             IsReadOnly="True" />
                </HeaderedContentControl>

                <HeaderedContentControl Header="اسم المجموعة">
                    <TextBox Text="{Binding Path=Entity.GroupName, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Validation.ErrorTemplate="{StaticResource ValidationTemplate}">

                    </TextBox>
                </HeaderedContentControl>

                <HeaderedContentControl Header="تفعيل">
                    <CheckBox IsChecked="{Binding Path=Entity.IsEnabled}" />
                </HeaderedContentControl>

                <HeaderedContentControl Header="ملاحظات">
                    <TextBox Text="{Binding Path=Entity.Notes, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                </HeaderedContentControl>

                <HeaderedContentControl Header="تاريخ الإنشاء">
                    <DatePicker Text="{Binding Path=Entity.CreateDate, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                </HeaderedContentControl>
            </StackPanel>
            <Label Content="إذا أردت إنشاء مجموعة جديدة\r\nقم بالضغط على زر جديد أولا."
                   VerticalContentAlignment="Center"
                   HorizontalContentAlignment="Center"
                   Background="White"
                   Opacity=".7"
                   Visibility="{Binding Path=Entity, Converter={StaticResource nullConverter}}" />
        </Grid>
    </Grid>
</UserControl>
